//
//  tun.h
//  myvpn
//
//  Created by Zhuobin He on 12-12-31.
//  Copyright (c) 2012年 Zhuobin He. All rights reserved.
//

#ifndef myvpn_tun_h
#define myvpn_tun_h

#include "SysLib.h"

#include "Common.h"


struct _TunDev {
    char *dev;
    char *local_ip;
    char *remote_ip;
#ifndef OS_WIN
    int fd;
#else
    HANDLE handle;
    OVERLAPPED  *olRead;
    OVERLAPPED  *olWrite;
    bool reading;
    char *ifnum;
#endif
};
typedef struct _TunDev TunDev;
typedef TunDev * PTunDev;

PTunDev tundev_alloc(const char *dev);
void tundev_delete(PTunDev obj);

int tundev_ifconfig(PTunDev dev, const char *local_ip, const char *remote_ip);

void tundev_close(PTunDev dev);

int tundev_read(PTunDev dev, char *buffer, int limit);
int tundev_write(PTunDev dev, const char *data, int size);

int tundev_route(PTunDev dev, const char *address, int prefix);

#ifdef OS_WIN
#define TAP_COMPONENT_ID "tap0901"
#define TAP_COMPONENT_ID2 "tap0801"
#endif


#endif
